package com.isdepci.project.factor.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.factor.domain.ProductConsumables;
import com.isdepci.project.factor.service.IProductConsumablesService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 产品耗材Controller
 *
 * @author isdepci
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/factor/productConsumables")
public class ProductConsumablesController extends BaseController {

    @Autowired
    private IProductConsumablesService productConsumablesService;

    /**
     * 查询产品耗材列表
     */
    @PreAuthorize("@ss.hasPermi('factor:productConsumables:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ProductConsumables productConsumables) {
        startPage();
        List<ProductConsumables> list = productConsumablesService.selectProductConsumablesList(productConsumables);
        return getDataTable(list);
    }

    /**
     * 获取产品耗材详细信息
     */
    @PreAuthorize("@ss.hasPermi('factor:productConsumables:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productConsumablesService.selectProductConsumablesById(id));
    }

    /**
     * 新增产品耗材
     */
    @PreAuthorize("@ss.hasPermi('factor:productConsumables:add')")
    @Log(title = "产品耗材", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductConsumables productConsumables) {
        return toAjax(productConsumablesService.insertProductConsumables(productConsumables));
    }

    /**
     * 修改产品耗材
     */
    @PreAuthorize("@ss.hasPermi('factor:productConsumables:edit')")
    @Log(title = "产品耗材", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductConsumables productConsumables) {
        return toAjax(productConsumablesService.updateProductConsumables(productConsumables));
    }

    /**
     * 删除产品耗材
     */
    @PreAuthorize("@ss.hasPermi('factor:productConsumables:remove')")
    @Log(title = "产品耗材", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productConsumablesService.deleteProductConsumablesByIds(ids));
    }
}
